﻿using System;

namespace Utilities
{
    public class RelationalDatabase
    {
        public enum Databases
        {
            SqlServer,
            Oracle,
            Db2,
            PostgreSql,
            Access
        }

        public Databases Database { get; set; }

        public string Version { get; set; }

        public override string ToString()
        {
            return GetDatabaseName() + " " + Version;
        }

        public string GetAdoNetProviderName()
        {
            switch (Database)
            {
                case Databases.SqlServer: return "System.Data.SqlClient";
                //case Databases.Oracle: return "Oracle";
                //case Databases.Db2: return "DB2";
                case Databases.PostgreSql: return "Npgsql";
                //case Databases.Access: return "Access";
                default: throw new NotImplementedException();

            }
        }

        private string GetDatabaseName()
        {
            switch (Database)
            {
                case Databases.SqlServer: return "SQL Server";
                case Databases.Oracle: return "Oracle";
                case Databases.Db2: return "DB2";
                case Databases.PostgreSql: return "PostgreSQL";
                case Databases.Access: return "Access";
                default: throw new NotImplementedException();

            }
        }

        public static RelationalDatabase SqlServer2008R2 
        {
            get
            {
                return new RelationalDatabase
                {
                    Database = Databases.SqlServer,
                    Version = "2008R2"
                };
            }
        }

        public static RelationalDatabase PostgreSql9
        {
            get
            {
                return new RelationalDatabase
                {
                    Database = Databases.PostgreSql,
                    Version = "9"
                };
            }
        }

        public string GetAdoNetProviderMasterConnectionString()
        {
            switch (Database)
            {
                case Databases.SqlServer: return "Data Source=.;Initial Catalog=master;Integrated Security=SSPI;";
                //case Databases.Oracle: return "Oracle";
                //case Databases.Db2: return "DB2";
                //case Databases.PostgreSql: return "PostgreSQL";
                //case Databases.Access: return "Access";
                default: throw new NotImplementedException();
            }
            
        }

        public string GetAdoNetProviderCatalogConnectionString(string catalogName)
        {
            switch (Database)
            {
                case Databases.SqlServer: return string.Format("Data Source=.;Initial Catalog={0};Integrated Security=SSPI", catalogName);
                //case Databases.Oracle: return "Oracle";
                //case Databases.Db2: return "DB2";
                //case Databases.PostgreSql: return "PostgreSQL";
                //case Databases.Access: return "Access";
                default: throw new NotImplementedException();

            }
        }
    }
}
